package com.itheima03;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Xiao
 * @date 2021/7/17
 */
public class ListDemo04 {
    /**
     * 需求：
     * 分别使用ArrayList和LinkedList完成存储字符串并遍历。
     */
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("Hello");
        list.add("World");
        list.add("Java");
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println();
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println();
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            System.out.println(s);
        }
        System.out.println("---------------");
        LinkedList<String> list1 = new LinkedList<>();
        list1.add("世界");
        list1.add("你好");
        list1.add("Java");
        for (String s : list1) {
            System.out.println(s);
        }
        System.out.println();
        Iterator<String> it1 = list1.iterator();
        while (it1.hasNext()) {
            System.out.println(it1.next());
        }
        System.out.println();
        for (int i = 0; i < list1.size(); i++) {
            String s = list1.get(i);
            System.out.println(s);
        }
    }
}
